package xyf.p07.binsearch;

/**
 * ClassName: P0367_IsPerfectSquare
 * Description:
 * Author: xyf
 * Date: 9/7/22 5:14 PM
 * Version: 1.0
 **/
public class P0367_IsPerfectSquare
{
    public boolean isPerfectSquare(int num)
    {
        int start = 1;
        int end = num;
        while (start <= end)
        {
            int middle = (end - start) / 2 + start;
            if (middle * middle == num)
            {
                return true;
            }
            else if (middle * middle < num)
            {
                start = middle + 1;
            }
            else
            {
                end = middle - 1;
            }
        }
        return false;
    }
}